package org.glow.changgou.user.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.glow.changgou.user.dao.UndoLogMapper;
import org.glow.changgou.user.pojo.Provinces;
import org.glow.changgou.user.pojo.UndoLog;
import org.glow.changgou.user.service.UndoLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

import javax.annotation.Resource;
import java.util.List;

/****
 * @Author:admin
 * @Description:UndoLog业务层接口实现类
 * @Date 2022/10/02 22:36:27
 *****/
@Service
public class UndoLogServiceImpl extends ServiceImpl<UndoLogMapper,UndoLog> implements UndoLogService {

    @Resource
    private UndoLogMapper undoLogMapper;


    /**
     * UndoLog条件+分页查询
     * @param undoLog 查询条件
     * @param page 页码
     * @param size 页大小
     * @return 分页结果
     */
    @Override
    public Page<UndoLog> findPage(UndoLog undoLog, int page, int size){
        Page<UndoLog> pageInfo = new Page<>(page,size);
        LambdaQueryWrapper<UndoLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = getCondition(queryWrapper,undoLog);
        return undoLogMapper.selectPage(pageInfo,queryWrapper);
    }

    /**
     * UndoLog分页查询
     * @param page
     * @param size
     * @return
     */
    @Override
    public Page<UndoLog> findPage(int page, int size){
        Page<UndoLog> pageInfo = new Page<>(page,size);

        return undoLogMapper.selectPage(pageInfo,null);
    }

    /**
     * UndoLog条件查询
     * @param undoLog
     * @return
     */
    @Override
    public List<UndoLog> findList(UndoLog undoLog){

        LambdaQueryWrapper<UndoLog> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper = getCondition(queryWrapper,undoLog);
        return undoLogMapper.selectList(queryWrapper);
    }


    /**
     * UndoLog构建查询对象
     * @param undoLog
     * @return
     */
    public LambdaQueryWrapper<UndoLog> getCondition(LambdaQueryWrapper<UndoLog> queryWrapper, UndoLog undoLog){

        if(undoLog!=null){
            // 
            if(!StringUtils.isEmpty(undoLog.getId())){
//                    criteria.andEqualTo("id",undoLog.getId());
                    queryWrapper.eq(UndoLog::getId,undoLog.getId());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getBranchId())){
//                    criteria.andEqualTo("branchId",undoLog.getBranchId());
                    queryWrapper.eq(UndoLog::getBranchId,undoLog.getBranchId());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getXid())){
//                    criteria.andEqualTo("xid",undoLog.getXid());
                    queryWrapper.eq(UndoLog::getXid,undoLog.getXid());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getRollbackInfo())){
//                    criteria.andEqualTo("rollbackInfo",undoLog.getRollbackInfo());
            queryWrapper.eq(UndoLog::getRollbackInfo,undoLog.getRollbackInfo());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getLogStatus())){
//                    criteria.andEqualTo("logStatus",undoLog.getLogStatus());
                    queryWrapper.eq(UndoLog::getLogStatus,undoLog.getLogStatus());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getLogCreated())){
//                    criteria.andEqualTo("logCreated",undoLog.getLogCreated());
                    queryWrapper.eq(UndoLog::getLogCreated,undoLog.getLogCreated());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getLogModified())){
//                    criteria.andEqualTo("logModified",undoLog.getLogModified());
                    queryWrapper.eq(UndoLog::getLogModified,undoLog.getLogModified());
            }
            // 
            if(!StringUtils.isEmpty(undoLog.getExt())){
//                    criteria.andEqualTo("ext",undoLog.getExt());
                    queryWrapper.eq(UndoLog::getExt,undoLog.getExt());
            }
        }
        return queryWrapper;
    }

    /**
     * 删除
     * @param id
     */
    @Override
    public void delete(Long id){
        undoLogMapper.deleteById(id);
    }

    /**
     * 修改UndoLog
     * @param undoLog
     */
    @Override
    public void update(UndoLog undoLog){
        undoLogMapper.updateById(undoLog);
    }

    /**
     * 增加UndoLog
     * @param undoLog
     */
    @Override
    public void add(UndoLog undoLog){
        undoLogMapper.insert(undoLog);
    }

    /**
     * 根据ID查询UndoLog
     * @param id
     * @return
     */
    @Override
    public UndoLog findById(Long id){
        return  undoLogMapper.selectById(id);
    }

    /**
     * 查询UndoLog全部数据
     * @return
     */
    @Override
    public List<UndoLog> findAll() {
        return undoLogMapper.selectList(null);
    }
}
